package com.tiiime.bluetooth;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.widget.Toast;

public class test1 extends Activity{
	
	BluetoothAdapter btAdapter;
	BluetoothSocket btSocket;
	BluetoothDevice btDevice;
    OutputStream btOutputStream;
    InputStream btInputStream;
	String bt_mac;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test1);
		
	}
	void connectBT(){
		try{
            UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID
            btSocket = btDevice.createInsecureRfcommSocketToServiceRecord(uuid);
            btSocket.connect();
            btOutputStream = btSocket.getOutputStream();
            btInputStream = btSocket.getInputStream();
//            btnConnect.setText(R.string.disconnect);
            System.out.println("connecting...");
	    }
	    catch(IOException ex)
	    {
	            Toast.makeText(this, "R.string.bluetooth_connection_failed", Toast.LENGTH_LONG).show();
//	            btnConnect.setText(R.string.connect);
	            try {
	            	btSocket.close();
	            } catch (IOException closeException) {
	            	
	            }
	            return;                        
	    }
	}
    void closeBT() throws IOException
    {
            btOutputStream.close();
            btInputStream.close();
            btSocket.close();
    }
}
